/**
 * Created by leo on 5/30/16.
 */

var mongoose = require('mongoose');
var Schema = mongoose.Schema;
var ObjectId = Schema.ObjectId;


var roomSchema = mongoose.Schema({
    name: {
        type: String,
        require: true
    }
}, {
    collection: 'room',
    versionKey: false
});

var Room = module.exports = mongoose.model('Room', roomSchema);

// Get Rooms
module.exports.getRooms = function(callback, limit) {
    Room.find(callback).limit(limit);
}

// Get Room By Id
module.exports.getRoomById = function (id, callback) {
    Room.findById(id, callback);
}

// Add Room
module.exports.addRoom = function (room, callback) {
    Room.create(room, callback);
}

// Update Room
module.exports.updateRoom = function (id, room, options, callback) {
    var query = {_id: id};
    //var update = {
    //    name: room.name,
    //    devices: room.devices
    //}
    Room.findOneAndUpdate(query, room, options, callback);
}

// Delete Room
module.exports.removeRoom = function (id, callback) {
    var query = {_id: id};
    Room.remove(query, callback);
}
